package nl.stuq.webui;

import nl.stuq.model.PersonColor;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.Radio;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

public class DefaultFormDemo extends WebPage {

    public DefaultFormDemo() {
        PersonColor personColor = new PersonColor();

        Form form = new Form("form", new Model(personColor)){
            protected void onSubmit() {
                // Do something with the data
                info("Thanks!");
                PersonColor current = (PersonColor) this.getModelObject();
                info("You are '" + current.getName() + "' and your favorite color is '" + current.getColor() + "'");
            }
        };
        add(form);

        // FeedbackPanel
        FeedbackPanel feedback = new FeedbackPanel("feedback");
        form.add(feedback);
        
        // Textfield for entering a name
        TextField name = new TextField("name", new PropertyModel(personColor, "name"));

        name.setRequired(true);
        form.add(name);

        // Creating the RadioGroup with all radio buttons
        RadioGroup color = new RadioGroup("color", new PropertyModel(personColor, "color"));        
        color.add(new Radio("red", new Model("red")));
        color.add(new Radio("green", new Model("green")));
        color.add(new Radio("blue", new Model("blue")));

        color.setRequired(true);
        form.add(color);

        // Add the Save button
        form.add(new Button("saveButton", new Model("Save")));

        
        add(new BookmarkablePageLink("backLink", getApplication().getHomePage()));
    }
}